package com.whsxt.common;

import java.util.HashMap;
import java.util.Map;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;

import com.whsxt.domain.BillType;
@Aspect
@Component
@EnableAspectJAutoProxy
public class CacheAspect {

	private Map<String, Object> map = new HashMap<String, Object>();
	
	public final static String MAP_PREFIX = "billtype";
	
	@Around("execution(* com.whsxt.service.impl.BillTypeServiceImpl.getById(..))")
	public Object CacheAspectBills(ProceedingJoinPoint joinPoint) throws Throwable {
		Object[] args = joinPoint.getArgs();
		Integer typeId = (Integer) args[0];
		Object object = map.get(MAP_PREFIX+typeId);
		if(object != null) {
			System.out.println("缓存中有数据");
			return object;
		}
		System.out.println("缓存没有数据,再从数据中查");
		BillType proceed = (BillType) joinPoint.proceed();
		map.put(MAP_PREFIX+proceed.getId(),proceed);
		return proceed;
	}
	
	
	
}
